/*
*  Copyright 2012 m4f10
*
*  This file is part of uScan.
*  uScan is free software: you can redistribute it and/or modify it under the
*  terms of the GNU General Public License as published by the 
*  Free Software Foundation, either version 3 of the License, or (at your option)
*  any later version.
*
*    uScan is distributed in the hope that it will be useful, 
*    but WITHOUT ANY WARRANTY; without even the implied warranty of 
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* 
*    See the GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License 
*    along with uScan. If not, see http://www.gnu.org/licenses/.
*/
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uscan;

/**
 *
 * @author Asus
 */
public class UScanSettingsForm extends javax.swing.JFrame {
    UScanSettings settings;
    /**
     * Creates new form UScanSettingsForm
     */
    
    public UScanSettingsForm()
    {
        initComponents();
    }
    
    public UScanSettingsForm(UScanSettings settings)
    {
       // this.settings = settings;
        initComponents();
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tInjValue = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tRegExp = new javax.swing.JTextArea();
        bSaveSettings = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        tNumThread = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tUserAgent = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tCookie = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("Settings");

        jLabel2.setText("Value used for injection method: ");

        tInjValue.setText("1337");
        tInjValue.setToolTipText("");

        jLabel3.setText("Regular expression used to escape webpages with dynamic content:");

        tRegExp.setColumns(20);
        tRegExp.setRows(2);
        jScrollPane1.setViewportView(tRegExp);

        bSaveSettings.setText("Save settings");
        bSaveSettings.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bSaveSettingsMouseClicked(evt);
            }
        });

        jLabel4.setText("Number of threads: ");

        tNumThread.setText("4");
        tNumThread.setToolTipText("");
        tNumThread.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tNumThreadActionPerformed(evt);
            }
        });

        jLabel5.setText("Spoofed User-Agent:");

        tUserAgent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tUserAgentActionPerformed(evt);
            }
        });

        jLabel6.setText("Cookie content:");

        tCookie.setColumns(20);
        tCookie.setRows(5);
        jScrollPane2.setViewportView(tCookie);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tUserAgent)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tNumThread, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(29, 29, 29))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tInjValue)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(bSaveSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tUserAgent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tInjValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tNumThread, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(bSaveSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bSaveSettingsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bSaveSettingsMouseClicked
        
        this.settings.setDefaultInjectedParamValue(this.tInjValue.getText());
        this.settings.setDynamicPageRegExp(this.tRegExp.getText());
        this.settings.setNumThread(Integer.parseInt(this.tNumThread.getText()));
        this.settings.setDefaultUserAgent(this.tUserAgent.getText());
        this.settings.setCookieValue(this.tCookie.getText());
        this.setVisible(false);
        
    }//GEN-LAST:event_bSaveSettingsMouseClicked

    private void tNumThreadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tNumThreadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tNumThreadActionPerformed

    private void tUserAgentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tUserAgentActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tUserAgentActionPerformed

    /**
     * @param args the command line arguments
     */
    public void main(UScanSettings settings) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        this.settings = settings;
        this.tInjValue.setText(this.settings.getDefaultInjectedParamValue());
        this.tRegExp.setText(this.settings.getDynamicPageRegExp());
        this.tNumThread.setText(String.valueOf(this.settings.getNumThread()));
        this.tUserAgent.setText(this.settings.getDefaultUserAgent());
        this.tCookie.setText(this.settings.getCookieValue());
        
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UScanSettingsForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UScanSettingsForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UScanSettingsForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UScanSettingsForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        this.setVisible(true);
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bSaveSettings;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea tCookie;
    private javax.swing.JTextField tInjValue;
    private javax.swing.JTextField tNumThread;
    private javax.swing.JTextArea tRegExp;
    private javax.swing.JTextField tUserAgent;
    // End of variables declaration//GEN-END:variables
}
